package state;

/**
 * Context —— 自动售货机
 */
public class VendingMachine {
    private VendingMachineState state;

    public VendingMachine() {
        state = new NoCoinState();
    }

    public void insertCoin() {
        state.insertCoin();
        if (state instanceof NoCoinState) {
            state = new HasCoinState();
        }
    }

    public void selectProduct() {
        state.selectProduct();
        if (state instanceof HasCoinState) {
            state.dispense();
            state = new NoCoinState();
        }
    }

    public void dispense() {
        state.dispense();
    }
}
